package com.younion.action.manage;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.younion.common.base.BaseAction;
import com.younion.common.paginator.Paginator;

import cpcns.jhsks.util.MapCollectionUtils;

import com.younion.business.IMobileUpdateService;
import com.younion.vo.MobileUpdateVO;

/**
 * @author wells
*/
public class MobileUpdateAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	protected static final Log logger = LogFactory.getLog(MobileUpdateAction.class);

	private IMobileUpdateService mobileUpdateService = null;

	private MobileUpdateVO mobileUpdateVO = new MobileUpdateVO();

	private List<MobileUpdateVO> mobileUpdateList;// 结果集列表
	/**
	 * 列表：翻页区；数据区
	 */
	@SuppressWarnings("unchecked")
	public String listMobileUpdate() {
		try {
			Map paramMap = null;
			if (mobileUpdateVO != null) {
				paramMap = MapCollectionUtils.removeEmptyEntry(PropertyUtils.describe(mobileUpdateVO));
			}
			// 获取总记录数
			int total = mobileUpdateService.getCountByMap(paramMap);
			// 根据总记录数获取分页对象
			Paginator paginator = this.getPaginator(total);
			mobileUpdateList = mobileUpdateService.get(paramMap, paginator);
			// 保存分页对象
			this.savaPaginator(paginator);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
		}
		return SUCCESS;
	}

	/**
	 * 新增
	 */
	public String addMobileUpdate() {
		return SUCCESS;
	}

	/**
	 * 修改保存，调度Jsp
	 */
	public String editMobileUpdate() {
		try {
			mobileUpdateVO = mobileUpdateService.getById(mobileUpdateVO.getId().toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 保存动作
	 */
	public String saveMobileUpdate() {
		try {
			mobileUpdateVO = mobileUpdateService.save(mobileUpdateVO);
			this.addLog(4, "修改客户端版本更新", "修改客户端版本更新", this.getSessionUser());
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;
	}

	/**
	 * 删除
	 */
	public String deleteMobileUpdate() {
		try {
			String pkId = request.getParameter("key");
			mobileUpdateService.remove(Arrays.asList(pkId.split(",")));
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;
	}
	/**
	 * 查看鿴
	 */
	public String viewMobileUpdate() {
		try {
			String pkId = request.getParameter("key");  
			mobileUpdateVO = mobileUpdateService.getById(pkId);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			e.printStackTrace();
		}
		return SUCCESS;

	}

	public MobileUpdateVO getMobileUpdateVO() {
		return mobileUpdateVO;
	}

	public void setMobileUpdateVO(MobileUpdateVO mobileUpdateVO) {
		this.mobileUpdateVO = mobileUpdateVO;
	}

	public void setMobileUpdateService(IMobileUpdateService mobileUpdateService) {
		this.mobileUpdateService = mobileUpdateService;
	}

	public List<MobileUpdateVO> getMobileUpdateList() {
		return mobileUpdateList;
	}

	public void setMobileUpdateList(List<MobileUpdateVO> mobileUpdateList) {
		this.mobileUpdateList = mobileUpdateList;
	}

}